using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace Esercitazione_CG_1
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class MenuHelper : Microsoft.Xna.Framework.GameComponent
    {
        SpriteBatch help;
        SpriteFont font;
        bool active = false;
        KeyboardState _lastKeyboardState, _currentKeyboardState;
        Viewport defaultViewport;
        Texture2D helpMenu;

        public MenuHelper(Game game, Viewport defaultViewport)
            : base(game)
        {
            this.defaultViewport = defaultViewport;
            help = new SpriteBatch(game.GraphicsDevice);
            // TODO: Construct any child components here
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            font = Game.Content.Load<SpriteFont>("MyFont");
            // TODO: Add your initialization code here
            base.Initialize();
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here
            if (_lastKeyboardState == null && _currentKeyboardState == null)
            {
                _lastKeyboardState = _currentKeyboardState = Keyboard.GetState();
            }
            else
            {
                _lastKeyboardState = _currentKeyboardState;
                _currentKeyboardState = Keyboard.GetState();
            }

            if (_lastKeyboardState.IsKeyUp(Keys.H) && _currentKeyboardState.IsKeyDown(Keys.H))
            {
                active = !active;
                helpMenu = Game.Content.Load<Texture2D>("menu background");
            }
        }

        public void draw()
        {
            help.Begin();
            help.DrawString(font, "H: help menu", new Vector2(10, 10), Color.White);

            if (active)
            {
                Game.GraphicsDevice.Viewport = defaultViewport;
                help.Draw(helpMenu, new Vector2(100, 50), new Color(255, 255, 255, 0.8f));
            }

            help.End();
        }
    }
}
